//
// Created by zsago on 01/06/21.
//

#ifndef LIBYUV_LIBYUV_EXT_H
#define LIBYUV_LIBYUV_EXT_H

#include <jni.h>
#include <android/log.h>
#include <libyuv.h>
#include <ctime>

#define SUBSAMPLE(v, a) ((((v) + (a)-1)) / (a))
#define IS_ALIGNED(p, a) (!((uintptr_t)(p) & ((a)-1)))
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,"GL_LIBYUV",__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,"GL_LIBYUV",__VA_ARGS__)
#define GETTIME(t) gettimeofday(&t, nullptr)

#ifdef __cplusplus
extern "C" {
#endif

int ExceptionCheck(JNIEnv *env);

JNIEXPORT void JNICALL
Java_com_andova_libyuv_LibYUV_00024Companion_YUV422ToNV21(JNIEnv *env, jobject,
                                                          jobject src_y,
                                                          jobject src_u,
                                                          jobject src_v,
                                                          jbyteArray dst_yuv,
                                                          jint angle, jint width, jint height);

JNIEXPORT jbyteArray JNICALL
Java_com_andova_libyuv_LibYUV_00024Companion_GetByteArray(JNIEnv *env, jobject, jobject src, jint len);

JNIEXPORT void JNICALL
Java_com_andova_libyuv_LibYUV_00024Companion_RotateNV21(JNIEnv *env, jobject,
                                                        jbyteArray src, jbyteArray dst,
                                                        jint angle, jint width, jint height);

void YUV422ToNV21(const uint8_t *src_y, int src_stride_y,
                  const uint8_t *src_u, int src_stride_u,
                  const uint8_t *src_v, int src_stride_v,
                  uint8_t *dst_y, int dst_stride_y,
                  uint8_t *dst_vu, int dst_stride_vu,
                  int width, int height);

void RotateNV21(uint8_t *src, uint8_t *dst, jint angle, jint width, jint height);

void RotateYUV(const uint8_t *src_y, uint8_t *dst_y,
               const uint8_t *src_u, uint8_t *dst_u,
               const uint8_t *src_v, uint8_t *dst_v,
               int angle, int width, int height);

[[deprecated("Inefficient")]]void YUV420Rotate90(uint8_t *dst, const uint8_t *src, int src_width, int src_height);

#ifdef __cplusplus
}
#endif

#endif //LIBYUV_LIBYUV_EXT_H
